# include "GUI.h"

# include "Game.h"
# include "Module.h"
# include "Renderer.h"

# include "World.h"
# include "Hero.h"
# include "PNJ.h"
# include "Inventory.h"
# include "Equipment.h"
# include "ObjectInventory.h"
# include "Armor.h"
# include "Weapon.h"
# include "Shield.h"
# include "Jewel.h"
# include "Quests.h"

GUI::GUI( Game* game) : Module( game), myCeguiRenderer( 0)
{

}

GUI::~GUI()
{

}

void GUI::setWorld( World* world)
{
	myWorld = world;
	myHero = myWorld->getHero();
}

bool GUI::init( Renderer* renderer)
{
	myRenderer = renderer;

	myCeguiRenderer = &CEGUI::OgreRenderer::bootstrapSystem();

	CEGUI::Imageset::setDefaultResourceGroup( "Imagesets");
	CEGUI::Font::setDefaultResourceGroup( "Fonts");
	CEGUI::Scheme::setDefaultResourceGroup( "Schemes");
	CEGUI::WidgetLookManager::setDefaultResourceGroup( "LookNFeel");
	CEGUI::WindowManager::setDefaultResourceGroup( "Layout");

	CEGUI::SchemeManager::getSingleton().create( "GlossySerpent.scheme");
	
	CEGUI::Point mousePosTmp = CEGUI::MouseCursor::getSingleton().getPosition();
	CEGUI::System::getSingleton().injectMouseMove( -mousePosTmp.d_x, -mousePosTmp.d_y);
	CEGUI::System::getSingleton().setDefaultMouseCursor( "GlossySerpentCursors", "MouseArrow");

	CEGUI::WindowManager& windowManagerTmp = CEGUI::WindowManager::getSingleton();
	CEGUI::Window* sheetTmp = windowManagerTmp.createWindow( "DefaultWindow", SHEET_BASE);
	CEGUI::System::getSingleton().setGUISheet( sheetTmp);

	myWindowManager = CEGUI::WindowManager::getSingletonPtr();

	return true;
}

void GUI::oneFrame()
{
	handleEvents();
}

CEGUI::Window* GUI::findWindow( CEGUI::String& name)
{
	if ( myWindowManager->isWindowPresent( name) )
	{
		return myWindowManager->getWindow( name);
	}

	return NULL;
}

void GUI::handleEvents()
{
	while ( !myEvents.empty() )
	{
		Event evtTmp = myEvents.front();
		myEvents.pop();

		if ( evtTmp.message == CREATE_MENU )
		{
			myState = MENU_STATE;
			createMenu();
		}

		else if ( evtTmp.message == NEW_GAME )
		{
			myState = GUI_STATE;
			createGame();
		}

		else if ( evtTmp.message == CREATE_GAME_MENU )
		{
			myState = GUI_STATE;
			createGameMenu();
		}

		else if ( evtTmp.message == RETURN_GAME )
		{
			myState = GAME_STATE;
		}

		else if ( evtTmp.message == OPEN_COMPETENCE )
		{
			createGameCompetence();
		}

		else if ( evtTmp.message == OPEN_INVENTORY )
		{
			createGameInventory();
		}

		else if ( evtTmp.message == RETURN_MENU )
		{
			myState = MENU_STATE;
			createMenu();
		}

		else if ( evtTmp.message == OPEN_TALK )
		{
			myState = GUI_STATE;
			createGameTalk();
		}

		else if ( evtTmp.message == CLOSE_GUI_WINDOW )
		{
			closeWindowOpen();
		}

		else if ( evtTmp.message == CLOSE_TALK )
		{
			myState = GAME_STATE;
		}

		else if ( evtTmp.message == OPEN_QUEST )
		{
			myState = GUI_STATE;
			createGameQuest();
		}

		else if ( evtTmp.message == CLOSE_QUEST )
		{
			myState = GAME_STATE;
		}

		else if ( evtTmp.message == HERO_DEATH )
		{
			myState = GUI_STATE;
			createGameDeath();
		}
	}
}

void GUI::createMenu()
{	
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetMenuTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_MENU);
	sheetTmp->addChildWindow( sheetMenuTmp);

	CEGUI::Window* newGameTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_MENU + "NewGameButton");
	newGameTmp->setText( "New Game");
	newGameTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	newGameTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim(0.425f, 0)));
	sheetMenuTmp->addChildWindow( newGameTmp);
	newGameTmp->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::newGame, this));

	CEGUI::Window* loadGameTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_MENU + "LoadGameButton");
	loadGameTmp->setText( "Load Game");
	loadGameTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	loadGameTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.475f, 0)));
	sheetMenuTmp->addChildWindow( loadGameTmp);
	loadGameTmp->subscribeEvent( CEGUI ::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::loadGame, this));

	CEGUI::Window* quitTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_MENU + "QuitButton");
	quitTmp->setText( "Quit");
	quitTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	quitTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.525f, 0)));
	sheetMenuTmp->addChildWindow( quitTmp);
	quitTmp->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::quit, this));
}

void GUI::createGame()
{
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);
	
	CEGUI::Window* sheetGameTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME);
	sheetTmp->addChildWindow( sheetGameTmp);

	CEGUI::Window* nameTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME + "Name");
	nameTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.0f, 0)));
	nameTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	sheetGameTmp->addChildWindow( nameTmp);

	CEGUI::ProgressBar* lifeTmp = (CEGUI::ProgressBar*) myWindowManager->createWindow( "GlossySerpent/ProgressBar", SHEET_BASE + SHEET_GAME + "Life");
	lifeTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.05f, 0)));
	lifeTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.025f, 0)));
	lifeTmp->setVisible( false);
	sheetGameTmp->addChildWindow( lifeTmp);

	CEGUI::ProgressBar* lifeHeroTmp = (CEGUI::ProgressBar*) myWindowManager->createWindow( "GlossySerpent/ProgressBar", SHEET_BASE + SHEET_GAME + "LifeHero");
	lifeHeroTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.025f, 0), CEGUI::UDim( 0.825f, 0)));
	lifeHeroTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	sheetGameTmp->addChildWindow( lifeHeroTmp);
	myHero->setLifeBar( lifeHeroTmp);

	CEGUI::ProgressBar* manaHeroTmp = (CEGUI::ProgressBar*) myWindowManager->createWindow( "GlossySerpent/ProgressBar", SHEET_BASE + SHEET_GAME + "ManaHero");
	manaHeroTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.025f, 0), CEGUI::UDim( 0.875f, 0)));
	manaHeroTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	manaHeroTmp->setProperty( "BarFillColour", "FF0000FF");
	sheetGameTmp->addChildWindow( manaHeroTmp);
	myHero->setManaBar( manaHeroTmp);
}

void GUI::createGameMenu()
{
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetGameMenuTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME_MENU);
	sheetTmp->addChildWindow( sheetGameMenuTmp);
	
	CEGUI::Window* returnGameTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_GAME_MENU + "ReturnGameButton");
	returnGameTmp->setText( "Return To Game");
	returnGameTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	returnGameTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim(0.425f, 0)));
	sheetGameMenuTmp->addChildWindow( returnGameTmp);
	returnGameTmp->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::returnGame, this));

	CEGUI::Window* returnMenuTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_GAME_MENU + "ReturnMenuButton");
	returnMenuTmp->setText( "Return To Menu");
	returnMenuTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	returnMenuTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.475f, 0)));
	sheetGameMenuTmp->addChildWindow( returnMenuTmp);
	returnMenuTmp->subscribeEvent( CEGUI ::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::returnMenu, this));

	CEGUI::Window* quitTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_GAME_MENU + "QuitButton");
	quitTmp->setText( "Quit");
	quitTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	quitTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.525f, 0)));
	sheetGameMenuTmp->addChildWindow( quitTmp);
	quitTmp->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::quit, this));
}

void GUI::createGameDeath()
{
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetGameDeathTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME_DEATH);
	sheetTmp->addChildWindow( sheetGameDeathTmp);

	CEGUI::Window* badNewsTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_DEATH + "BadNews");
	badNewsTmp->setText( "You are dead");
	badNewsTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	badNewsTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.425f, 0)));
	sheetGameDeathTmp->addChildWindow( badNewsTmp);
	
	CEGUI::Window* returnMenuTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_GAME_DEATH + "ReturnMenuButton");
	returnMenuTmp->setText( "Return To Menu");
	returnMenuTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	returnMenuTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.475f, 0)));
	sheetGameDeathTmp->addChildWindow( returnMenuTmp);
	returnMenuTmp->subscribeEvent( CEGUI ::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::returnMenu, this));

	CEGUI::Window* quitTmp = myWindowManager->createWindow( "GlossySerpent/Button", SHEET_BASE + SHEET_GAME_DEATH + "QuitButton");
	quitTmp->setText( "Quit");
	quitTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.15f, 0), CEGUI::UDim( 0.05f, 0)));
	quitTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.425f, 0), CEGUI::UDim( 0.525f, 0)));
	sheetGameDeathTmp->addChildWindow( quitTmp);
	quitTmp->subscribeEvent( CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber( &GUI::quit, this));
}

void GUI::createGameInventory()
{
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetGameInventoryTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME_INVENTORY);
	sheetTmp->addChildWindow( sheetGameInventoryTmp);

	CEGUI::Window* windowTmp = myWindowManager->createWindow( "GlossySerpent/FrameWindow", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow");
	windowTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.1f, 0), CEGUI::UDim( 0.1f, 0)));
	windowTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.8f, 0), CEGUI::UDim( 0.8f, 0))); 
	sheetGameInventoryTmp->addChildWindow( windowTmp);
	windowTmp->subscribeEvent( CEGUI::FrameWindow::EventCloseClicked, CEGUI::Event::Subscriber( &GUI::closeInventory, this));

	CEGUI::TabControl* tabWindowTmp = (CEGUI::TabControl*)myWindowManager->createWindow( "GlossySerpent/TabControl", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow");
	tabWindowTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.0f, 0), CEGUI::UDim( 0.0f, 0)));
	tabWindowTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.5f, 0), CEGUI::UDim( 1.0f, 0)));
	windowTmp->addChildWindow( tabWindowTmp);

	CEGUI::ItemListbox* panelWeaponsTmp = (CEGUI::ItemListbox*) myWindowManager->createWindow( "GlossySerpent/ItemListbox", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons");
	panelWeaponsTmp->setText( "Weapons");
	panelWeaponsTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 1.0f, 0), CEGUI::UDim( 1.0f, 0)));
	tabWindowTmp->addTab( panelWeaponsTmp);

	CEGUI::ItemListbox* panelShieldsTmp = (CEGUI::ItemListbox*) myWindowManager->createWindow( "GlossySerpent/ItemListbox", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelShields");
	panelShieldsTmp->setText( "Shields");
	panelShieldsTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 1.0f, 0), CEGUI::UDim( 1.0f, 0)));
	tabWindowTmp->addTab( panelShieldsTmp);
	
	CEGUI::ItemListbox* panelArmorsTmp = (CEGUI::ItemListbox*) myWindowManager->createWindow( "GlossySerpent/ItemListbox", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors");
	panelArmorsTmp->setText( "Armors");
	panelArmorsTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 1.0f, 0), CEGUI::UDim( 1.0f, 0)));
	tabWindowTmp->addTab( panelArmorsTmp);

	CEGUI::ItemListbox* panelJewelsTmp = (CEGUI::ItemListbox*) myWindowManager->createWindow( "GlossySerpent/ItemListbox", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels");
	panelJewelsTmp->setText( "Jewels");
	panelJewelsTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 1.0f, 0), CEGUI::UDim( 1.0f, 0)));
	tabWindowTmp->addTab( panelJewelsTmp);
	
	Inventory* inventoryTmp = myHero->getInventory();

	if ( !inventoryTmp->isSwordsEmpty() )
	{
		CEGUI::ItemEntry* swordTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons/SwordsSep");
		swordTmp->setText( "------------------ Swords ------------------");
		panelWeaponsTmp->addItem( swordTmp);

		std::map<std::string, Weapon*>& swordsTmp = inventoryTmp->getSwords();

		for ( std::map<std::string, Weapon*>::iterator it = swordsTmp.begin(); it != swordsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelWeaponsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isAxesEmpty() )
	{
		CEGUI::ItemEntry* axeTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons/AxesSep");
		axeTmp->setText( "------------------ Axes ------------------");
		panelWeaponsTmp->addItem( axeTmp);

		std::map<std::string, Weapon*>& axesTmp = inventoryTmp->getAxes();

		for ( std::map<std::string, Weapon*>::iterator it = axesTmp.begin(); it != axesTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelWeaponsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isShieldsEmpty() )
	{
		CEGUI::ItemEntry* shieldTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelShields/ShieldSep");
		shieldTmp->setText( "------------------ Shields ------------------");
		panelShieldsTmp->addItem( shieldTmp);

		std::map<std::string, Shield*>& shieldsTmp = inventoryTmp->getShields();

		for ( std::map<std::string, Shield*>::iterator it = shieldsTmp.begin(); it != shieldsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelShields/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelShieldsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}
	
	if ( !inventoryTmp->isHeadArmorsEmpty() )
	{
		CEGUI::ItemEntry* headArmorTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/HeadArmorSep");
		headArmorTmp->setText( "------------------ Helmets ------------------");
		panelArmorsTmp->addItem( headArmorTmp);

		std::map<std::string, Armor*>& headArmorsTmp = inventoryTmp->getHeadArmors();

		for ( std::map<std::string, Armor*>::iterator it = headArmorsTmp.begin(); it != headArmorsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelArmorsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}
	
	if ( !inventoryTmp->isBodyArmorsEmpty() )
	{
		CEGUI::ItemEntry* bodyArmorTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/BodyArmorSep");
		bodyArmorTmp->setText( "------------------ Body Armors ------------------");
		panelArmorsTmp->addItem( bodyArmorTmp);

		std::map<std::string, Armor*>& bodyArmorsTmp = inventoryTmp->getBodyArmors();

		for ( std::map<std::string, Armor*>::iterator it = bodyArmorsTmp.begin(); it != bodyArmorsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelArmorsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isArmsArmorsEmpty() )
	{
		CEGUI::ItemEntry* armsArmorTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/ArmsArmorSep");
		armsArmorTmp->setText( "------------------ Arms Armors ------------------");
		panelArmorsTmp->addItem( armsArmorTmp);

		std::map<std::string, Armor*>& armsArmorsTmp = inventoryTmp->getArmsArmors();

		for ( std::map<std::string, Armor*>::iterator it = armsArmorsTmp.begin(); it != armsArmorsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelArmorsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isHipsArmorsEmpty() )
	{
		CEGUI::ItemEntry* hipsArmorTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/HipsArmorSep");
		hipsArmorTmp->setText( "------------------ Hips Armors ------------------");
		panelArmorsTmp->addItem( hipsArmorTmp);

		std::map<std::string, Armor*>& hipsArmorsTmp = inventoryTmp->getHipsArmors();

		for ( std::map<std::string, Armor*>::iterator it = hipsArmorsTmp.begin(); it != hipsArmorsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelArmorsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isFeetArmorsEmpty() )
	{
		CEGUI::ItemEntry* feetArmorTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/FeetArmorSep");
		feetArmorTmp->setText( "------------------ Greaves ------------------");
		panelArmorsTmp->addItem( feetArmorTmp);

		std::map<std::string, Armor*>& feetArmorsTmp = inventoryTmp->getFeetArmors();

		for ( std::map<std::string, Armor*>::iterator it = feetArmorsTmp.begin(); it != feetArmorsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelArmorsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isNecklacesEmpty() )
	{
		CEGUI::ItemEntry* necklaceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels/NecklaceSep");
		necklaceTmp->setText( "------------------ Necklaces ------------------");
		panelJewelsTmp->addItem( necklaceTmp);

		std::map<std::string, Jewel*>& necklacesTmp = inventoryTmp->getNecklaces();

		for ( std::map<std::string, Jewel*>::iterator it = necklacesTmp.begin(); it != necklacesTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelJewelsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	if ( !inventoryTmp->isRingsEmpty() )
	{
		CEGUI::ItemEntry* ringTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels/RingSep");
		ringTmp->setText( "------------------ Rings ------------------");
		panelJewelsTmp->addItem( ringTmp);

		std::map<std::string, Jewel*>& ringsTmp = inventoryTmp->getRings();

		for ( std::map<std::string, Jewel*>::iterator it = ringsTmp.begin(); it != ringsTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels/" + it->second->getName());
			pieceTmp->setText( it->second->getName());
			panelJewelsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseEnters, CEGUI::Event::Subscriber( &GUI::mouseMovedInventory, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseLeaves, CEGUI::Event::Subscriber( &GUI::clearPanelComp, this));
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickInventory, this));
		} 
	}

	CEGUI::Window* panelCompTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/PanelComp");
	panelCompTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.2f, 0), CEGUI::UDim( 0.4f, 0)));
	panelCompTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.525f, 0), CEGUI::UDim( 0.6f, 0)));
	windowTmp->addChildWindow( panelCompTmp);

	CEGUI::Window* panelCompUsedTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/PanelCompUsed");
	panelCompUsedTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.2f, 0), CEGUI::UDim( 0.4f, 0)));
	panelCompUsedTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.75f, 0), CEGUI::UDim( 0.6f, 0)));
	windowTmp->addChildWindow( panelCompUsedTmp);
}

void GUI::createGameCompetence()
{
	std::ostringstream strTmp;
	
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetGameCompetenceTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME_COMPETENCE);
	sheetTmp->addChildWindow( sheetGameCompetenceTmp);

	CEGUI::Window* windowTmp = myWindowManager->createWindow( "GlossySerpent/FrameWindow", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow");
	windowTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.1f, 0), CEGUI::UDim( 0.1f, 0)));
	windowTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.8f, 0), CEGUI::UDim( 0.8f, 0))); 
	sheetGameCompetenceTmp->addChildWindow( windowTmp);
	windowTmp->subscribeEvent( CEGUI::FrameWindow::EventCloseClicked, CEGUI::Event::Subscriber( &GUI::closeCompetence, this));

	strTmp << myHero->getStrength();
	CEGUI::Window* strenghtTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/StrengthText");
	strenghtTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	strenghtTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.05f, 0)));
	strenghtTextTmp->setText( "Strength : " + strTmp.str());
	windowTmp->addChildWindow( strenghtTextTmp);

	strTmp.str("");
	strTmp << myHero->getAgility();
	CEGUI::Window* agilityTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/AgilityText");
	agilityTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	agilityTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.15f, 0)));
	agilityTextTmp->setText( "Agility : " + strTmp.str());
	windowTmp->addChildWindow( agilityTextTmp);

	strTmp.str("");
	strTmp << myHero->getStamina();
	CEGUI::Window* staminaTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/StaminaText");
	staminaTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	staminaTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.25f, 0)));
	staminaTextTmp->setText( "Stamina : " + strTmp.str());
	windowTmp->addChildWindow( staminaTextTmp);

	strTmp.str("");
	strTmp << myHero->getPower();
	CEGUI::Window* powerTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/PowerText");
	powerTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	powerTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.35f, 0)));
	powerTextTmp->setText( "Power : " + strTmp.str());
	windowTmp->addChildWindow( powerTextTmp);

	strTmp.str("");
	strTmp << myHero->getCurrentLife() << " / " << myHero->getLife();

	CEGUI::Window* lifeTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/LifeText");
	lifeTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	lifeTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.30f, 0), CEGUI::UDim( 0.20f, 0)));
	lifeTextTmp->setText( "Life : " + strTmp.str());
	windowTmp->addChildWindow( lifeTextTmp);

	strTmp.str("");
	strTmp << myHero->getCurrentMana() << " / " << myHero->getMana();

	CEGUI::Window* manaTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/ManaText");
	manaTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	manaTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.30f, 0), CEGUI::UDim( 0.30f, 0)));
	manaTextTmp->setText( "Mana : " + strTmp.str());
	windowTmp->addChildWindow( manaTextTmp);

	strTmp.str( "");
	strTmp << myHero->getLevel();
	
	CEGUI::Window* levelTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/LevelText");
	levelTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.10f, 0), CEGUI::UDim( 0.05f, 0)));
	levelTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.45f, 0)));
	levelTextTmp->setText( "Level : " + strTmp.str());
	windowTmp->addChildWindow( levelTextTmp);

	strTmp.str( "");
	strTmp << myHero->getExperience() << " / " << myHero->getNextExperience();

	CEGUI::Window* expTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/ExpText");
	expTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.10f, 0), CEGUI::UDim( 0.05f, 0)));
	expTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.175f, 0), CEGUI::UDim( 0.45f, 0)));
	expTextTmp->setText( strTmp.str());
	windowTmp->addChildWindow( expTextTmp);

	CEGUI::ProgressBar* expBarTmp = (CEGUI::ProgressBar*) myWindowManager->createWindow( "GlossySerpent/ProgressBar", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/ExpBar");
	expBarTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.30f, 0), CEGUI::UDim( 0.05f, 0)));
	expBarTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.35f, 0), CEGUI::UDim( 0.45f, 0)));
	expBarTmp->setProgress( (float) myHero->getExperience() / (float) myHero->getNextExperience());
	windowTmp->addChildWindow( expBarTmp);

	strTmp.str( "");
	strTmp << myHero->getPointsCharac();

	CEGUI::Window* pointsCharacTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/PointsCharacText");
	pointsCharacTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	pointsCharacTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.55f, 0)));
	pointsCharacTextTmp->setText("Points : " + strTmp.str());
	windowTmp->addChildWindow( pointsCharacTextTmp);

	strTmp.str( "");
	strTmp << myHero->getPointsPower();

	CEGUI::Window* pointsPowerTextTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_COMPETENCE + "FrameWindow/PointsPowerText");
	pointsPowerTextTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.20f, 0), CEGUI::UDim( 0.05f, 0)));
	pointsPowerTextTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.65f, 0)));
	pointsPowerTextTmp->setText("Points : " + strTmp.str());
	windowTmp->addChildWindow( pointsPowerTextTmp);
}

void GUI::createGameQuest()
{
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetGameQuestTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME_QUEST);
	sheetTmp->addChildWindow( sheetGameQuestTmp);

	CEGUI::Window* windowTmp = myWindowManager->createWindow( "GlossySerpent/FrameWindow", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow");
	windowTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.8f, 0), CEGUI::UDim( 0.8f, 0)));
	windowTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.1f, 0), CEGUI::UDim( 0.1f, 0)));
	sheetGameQuestTmp->addChildWindow( windowTmp);
	windowTmp->subscribeEvent( CEGUI::FrameWindow::EventCloseClicked, CEGUI::Event::Subscriber( &GUI::closeQuest, this));

	CEGUI::ItemListbox* listQuestsTmp = (CEGUI::ItemListbox*) myWindowManager->createWindow( "GlossySerpent/ItemListbox", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/listQuests");
	listQuestsTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.4f, 0), CEGUI::UDim( 0.9f, 0)));
	listQuestsTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.05f, 0)));
	windowTmp->addChildWindow( listQuestsTmp);

	CEGUI::Window* questPathTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/questPath");
	questPathTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.4f, 0), CEGUI::UDim( 0.5f, 0)));
	questPathTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.55f, 0), CEGUI::UDim( 0.05f, 0)));
	questPathTmp->setProperty( "VertFormatting", "TopAligned");
	windowTmp->addChildWindow( questPathTmp);

	CEGUI::Window* questDetailTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/questDetail");
	questDetailTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.4f, 0), CEGUI::UDim( 0.3f, 0)));
	questDetailTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.55f, 0), CEGUI::UDim( 0.60f, 0)));
	questDetailTmp->setProperty( "VertFormatting", "TopAligned");
	windowTmp->addChildWindow( questDetailTmp);

	Quests* questsTmp = myHero->getQuests();

	if ( !questsTmp->isCurrentEmpty() )
	{	
		CEGUI::ItemEntry* questActiveTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/listQuests/Active");
		questActiveTmp->setText( "-------- Quests Active --------");
		listQuestsTmp->addItem( questActiveTmp);

		std::map<std::string, Quest*>& questsCurrentTmp = questsTmp->getQuestsCurrent();

		for ( std::map<std::string, Quest*>::iterator it = questsCurrentTmp.begin(); it != questsCurrentTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/listQuests/" + it->first);
			pieceTmp->setText( it->first);
			listQuestsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventActivated, CEGUI::Event::Subscriber( &GUI::detailQuest, this));
		}
	}

	if ( !questsTmp->isDoneEmpty() )
	{
		CEGUI::ItemEntry* questDoneTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/listQuests/Done");
		questDoneTmp->setText( "-------- Quests Done --------");
		listQuestsTmp->addItem( questDoneTmp);

		std::map<std::string, Quest*>& questsDoneTmp = questsTmp->getQuestsDone();

		for ( std::map<std::string, Quest*>::iterator it = questsDoneTmp.begin(); it != questsDoneTmp.end(); it++ )
		{
			CEGUI::ItemEntry* pieceTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/listQuests/" + it->first);
			pieceTmp->setText( it->first);
			listQuestsTmp->addItem( pieceTmp);
			pieceTmp->subscribeEvent( CEGUI::ItemEntry::EventActivated, CEGUI::Event::Subscriber( &GUI::detailQuest, this));
		}
	}
}

void GUI::createGameTalk()
{
	CEGUI::Window* sheetTmp = myWindowManager->getWindow( SHEET_BASE);

	CEGUI::Window* sheetGameTalkTmp = myWindowManager->createWindow( "DefaultWindow", SHEET_BASE + SHEET_GAME_TALK);
	sheetTmp->addChildWindow( sheetGameTalkTmp);

	CEGUI::Window* windowTmp = myWindowManager->createWindow( "GlossySerpent/SimplePanel", SHEET_BASE + SHEET_GAME_TALK + "Window");
	windowTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.80f, 0), CEGUI::UDim( 0.30f, 0)));
	windowTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.10f, 0), CEGUI::UDim( 0.60f, 0)));
	sheetGameTalkTmp->addChildWindow( windowTmp);

	CEGUI::Window* textPnjTmp = myWindowManager->createWindow( "GlossySerpent/StaticText", SHEET_BASE + SHEET_GAME_TALK + "Window/TextPNJ");
	textPnjTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.90f, 0), CEGUI::UDim( 0.25f, 0)));
	textPnjTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.05f, 0)));
	windowTmp->addChildWindow( textPnjTmp);

	CEGUI::ItemListbox* panelAnswersTmp = (CEGUI::ItemListbox*) myWindowManager->createWindow( "GlossySerpent/ItemListbox", SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers");
	panelAnswersTmp->setSize( CEGUI::UVector2( CEGUI::UDim( 0.90f, 0), CEGUI::UDim( 0.55f, 0)));
	panelAnswersTmp->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.05f, 0), CEGUI::UDim( 0.35f, 0)));
	windowTmp->addChildWindow( panelAnswersTmp);

	addDialog( myHero->getTalk()->findPieceDialog( myHero->getTalk()->getCurrentDialog()));
}

void GUI::closeWindowOpen()
{
	bool windowClosedTmp = false;

	if ( myWindowManager->isWindowPresent( SHEET_BASE + SHEET_GAME_COMPETENCE) )
	{
		myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_COMPETENCE);
		windowClosedTmp = true;
	}

	else if ( myWindowManager->isWindowPresent( SHEET_BASE + SHEET_GAME_INVENTORY) )
	{
		myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_COMPETENCE);
		windowClosedTmp = true;
	}

	else if ( myWindowManager->isWindowPresent( SHEET_BASE + SHEET_GAME_TALK) )
	{
		myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_TALK);
		windowClosedTmp = true;
	}

	if ( windowClosedTmp )
	{
		myState = GAME_STATE;
		
		Event evtTmp;

		evtTmp.message = CLOSE_GUI_WINDOW;
		myGame->receiveEvent( evtTmp);
	}
}

void GUI::addDialog( PieceDialog* pieceDialog)
{
	switch ( pieceDialog->action )
	{
		case NORMAL:
		{
			std::ostringstream strTmp;
			strTmp.str( "");
	
			CEGUI::Window* textPnjTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/TextPNJ");
			CEGUI::ItemListbox* panelAnswersTmp = (CEGUI::ItemListbox*) myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers");
	
			while ( panelAnswersTmp->getItemCount() )
			{
				panelAnswersTmp->removeItem( panelAnswersTmp->getItemFromIndex( 0));
			}

			textPnjTmp->setText( pieceDialog->pnjTalk);

			for ( unsigned int i = 0; i < pieceDialog->answers.size(); i++ )
			{
				strTmp << i;

				CEGUI::ItemEntry* answerTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers/" + strTmp.str());
				answerTmp->setText( *pieceDialog->answers[i]);
				panelAnswersTmp->addItem( answerTmp);
				answerTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickMouseDialog, this));

				strTmp.str( "");
			}
		}
		break;

		case ACTIVE_QUEST:
		{
			myHero->getQuests()->activeQuest( (*pieceDialog->questName).c_str());
			myHero->getTalk()->addQuestActivated( *pieceDialog->questName);
			
			std::ostringstream strTmp;
			strTmp.str( "");
	
			CEGUI::Window* textPnjTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/TextPNJ");
			CEGUI::ItemListbox* panelAnswersTmp = (CEGUI::ItemListbox*) myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers");
	
			while ( panelAnswersTmp->getItemCount() )
			{
				panelAnswersTmp->removeItem( panelAnswersTmp->getItemFromIndex( 0));
			}

			textPnjTmp->setText( pieceDialog->pnjTalk);

			for ( unsigned int i = 0; i < pieceDialog->answers.size(); i++ )
			{
				strTmp << i;

				CEGUI::ItemEntry* answerTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers/" + strTmp.str());
				answerTmp->setText( *pieceDialog->answers[i]);
				panelAnswersTmp->addItem( answerTmp);
				answerTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickMouseDialog, this));

				strTmp.str( "");
			}
		}
		break;

		case NEXT_STEP_QUEST:
		{
			myHero->getQuests()->nextStepQuest( *pieceDialog->questName);
			myHero->getTalk()->addQuestActivated( *pieceDialog->questName);
			
			std::ostringstream strTmp;
			strTmp.str( "");
	
			CEGUI::Window* textPnjTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/TextPNJ");
			CEGUI::ItemListbox* panelAnswersTmp = (CEGUI::ItemListbox*) myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers");
	
			while ( panelAnswersTmp->getItemCount() )
			{
				panelAnswersTmp->removeItem( panelAnswersTmp->getItemFromIndex( 0));
			}

			textPnjTmp->setText( pieceDialog->pnjTalk);

			for ( unsigned int i = 0; i < pieceDialog->answers.size(); i++ )
			{
				strTmp << i;

				CEGUI::ItemEntry* answerTmp = (CEGUI::ItemEntry*) myWindowManager->createWindow( "GlossySerpent/ListboxItem", SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers/" + strTmp.str());
				answerTmp->setText( *pieceDialog->answers[i]);
				panelAnswersTmp->addItem( answerTmp);
				answerTmp->subscribeEvent( CEGUI::ItemEntry::EventMouseClick, CEGUI::Event::Subscriber( &GUI::clickMouseDialog, this));

				strTmp.str( "");
			}
		}
		break;

		case QUIT_DIALOG:
		{
			myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_TALK);

			Event evtTmp;

			evtTmp.message = CLOSE_TALK;
			myGame->receiveEvent( evtTmp);

			myHero->getTalk()->setCurrentDialog( *pieceDialog->destinations[0]);
			myHero->setTalk( NULL);
		}
		break;
	}
}

bool GUI::newGame( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_MENU);
	
	Event evtTmp;

	evtTmp.message = NEW_GAME;
	myGame->receiveEvent( evtTmp);

	return true;
}

bool GUI::loadGame( const CEGUI::EventArgs& e)
{
	return true;
}

bool GUI::quit( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE);
	
	Event evtTmp;
	evtTmp.message = QUIT;
	
	myGame->receiveEvent( evtTmp);

	return true;
}

bool GUI::returnGame( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_MENU);

	Event evtTmp;
	evtTmp.message = RETURN_GAME;

	myGame->receiveEvent( evtTmp);
	
	return true;
}

bool GUI::returnMenu( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME);
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_MENU);
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_DEATH);

	Event evtTmp;
	evtTmp.message = RETURN_MENU;

	myGame->receiveEvent( evtTmp);
	
	return true;
}

bool GUI::closeCompetence( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_COMPETENCE);

	Event evtTmp;
	evtTmp.message = CLOSE_COMPETENCE;

	myGame->receiveEvent( evtTmp);

	return true;
}

bool GUI::closeInventory( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_INVENTORY);

	Event evtTmp;
	evtTmp.message = CLOSE_INVENTORY;

	myGame->receiveEvent( evtTmp);

	return true;
}

bool GUI::mouseMovedInventory( const CEGUI::EventArgs& e)
{
	const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>( e);

	CEGUI::ItemEntry* objectTmp = ( CEGUI::ItemEntry*) we.window;
	CEGUI::Window* panelCompTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/PanelComp");
	CEGUI::Window* panelCompUsedTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/PanelCompUsed");

	Equipment* equipmentTmp = myHero->getEquipment();

	if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons" ) )
	{
		Weapon* weaponTmp = equipmentTmp->findActualWeapon();
		
		if ( weaponTmp )
		{
			panelCompUsedTmp->setText( weaponTmp->getName());
		}

		else
		{
			panelCompUsedTmp->setText( "");
		}
	}

	else if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelShields" ) )
	{
		Shield* shieldTmp = equipmentTmp->findActualShield();
		
		if ( shieldTmp )
		{
			panelCompUsedTmp->setText( shieldTmp->getName());
		}

		else
		{
			panelCompUsedTmp->setText( "");
		}
	}

	else if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors" ) )
	{
		Armor* armorTmp = equipmentTmp->findActualArmor( BODY_ARMOR);

		if ( armorTmp )
		{
			panelCompUsedTmp->setText( armorTmp->getName());
		}

		else
		{
			panelCompUsedTmp->setText( "");
		}
	}

	else if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels" ) )
	{
		Jewel* jewelTmp = equipmentTmp->findActualJewel( RING);

		if ( jewelTmp )
		{
			panelCompUsedTmp->setText( jewelTmp->getName());
		}

		else
		{
			panelCompUsedTmp->setText( "");
		}
	}

	panelCompTmp->setText( objectTmp->getText());
	return true;
}

bool GUI::clearPanelComp( const CEGUI::EventArgs& e)
{
	CEGUI::Window* panelCompTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/PanelComp");
	CEGUI::Window* panelCompUsedTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/PanelCompUsed");

	panelCompTmp->setText( "");
	panelCompUsedTmp->setText( "");

	return true;
}

bool GUI::clickInventory( const CEGUI::EventArgs& e)
{
	const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>( e);

	CEGUI::ItemEntry* objectTmp = ( CEGUI::ItemEntry*) we.window;

	if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelWeapons" ) )
	{
		myHero->equipWeapon( objectTmp->getText().c_str());
	}

	else if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelShields" ) )
	{
		myHero->equipShield( objectTmp->getText().c_str());
	}

	else if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelArmors" ) )
	{
		myHero->equipArmor( objectTmp->getText().c_str());
	}

	else if ( objectTmp->getParent()->getParent()->getName() == ( SHEET_BASE + SHEET_GAME_INVENTORY + "FrameWindow/TabWindow/PanelJewels" ) )
	{
		myHero->equipJewel( objectTmp->getText().c_str());
	}
	
	return true;
}

bool GUI::closeQuest( const CEGUI::EventArgs& e)
{
	myWindowManager->destroyWindow( SHEET_BASE + SHEET_GAME_QUEST);

	Event evtTmp;

	evtTmp.message = CLOSE_QUEST;
	myGame->receiveEvent( evtTmp);

	return true;
}

bool GUI::detailQuest( const CEGUI::EventArgs& e)
{
	const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>( e);

	CEGUI::Window* questPathTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/questPath");
	CEGUI::Window* questDetailTmp = myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_QUEST + "FrameWindow/questDetail");
	CEGUI::ItemEntry* objectTmp = (CEGUI::ItemEntry*) we.window;
	Quest* questTmp = myHero->getQuests()->findQuest( (objectTmp->getText()).c_str());

	std::ostringstream strTmp;

	for ( int i = 0; i <= questTmp->current; i++ )
	{
		strTmp << *questTmp->descriptions[i] << std::endl;
	}

	questPathTmp->setText( strTmp.str());
	questDetailTmp->setText( questTmp->description);
	
	return true;
}

bool GUI::clickMouseDialog( const CEGUI::EventArgs& e)
{
	const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>( e);
	
	CEGUI::ItemListbox* panelAnswersTmp = (CEGUI::ItemListbox*) myWindowManager->getWindow( SHEET_BASE + SHEET_GAME_TALK + "Window/PanelAnswers");
	CEGUI::ItemEntry* objectTmp = (CEGUI::ItemEntry*) we.window;
	unsigned int choiceTmp = panelAnswersTmp->getItemIndex( objectTmp);

	const std::string& currentDialogTmp = *(myHero->getTalk()->findPieceDialog( myHero->getTalk()->getCurrentDialog())->destinations[choiceTmp]);
	myHero->getTalk()->setCurrentDialog( currentDialogTmp);
	addDialog( myHero->getTalk()->findPieceDialog( currentDialogTmp));

	return true;
}